package com.ghsc.ghxc.jsb.ui.live.view.cust

import android.view.LayoutInflater
import android.view.View
import com.cn.appcore.event.RxBus
import com.cn.appcore.event.RxBusBean
import com.cn.appcore.ext.QuickAdapter
import com.cn.appcore.ext.loge
import com.cn.appcore.ext.setSingleClickListener
import com.cn.appcore.utils.GlideUtil
import com.ghsc.ghxc.jsb.R
import com.ghsc.ghxc.jsb.config.CustSignKey
import com.ghsc.ghxc.jsb.databinding.ImCustAnchorLiveViewBinding
import com.ghsc.ghxc.jsb.ui.live.bean.UserInfoTagAentBean
import com.netease.yunxin.kit.chatkit.ui.databinding.ChatBaseMessageViewHolderBinding
import com.netease.yunxin.kit.chatkit.ui.model.ChatMessageBean
import com.netease.yunxin.kit.chatkit.ui.normal.view.message.viewholder.NormalChatBaseMessageViewHolder

/**
 * 项目：GuoHuaJsb
 * 包名：com.ghsc.ghxc.jsb.ui.live.view.cust
 * 类名：CusAnchorLiveAttachmentViewHolder
 * 创建时间：2024/5/24 13:42
 * 创建人 @author： xiaolin
 * 描述 ：Todo...主播发红包，。通知粉丝
 */
class CusAnchorLiveAttachmentViewHolder (parent: ChatBaseMessageViewHolderBinding, viewType: Int) : NormalChatBaseMessageViewHolder(
    parent, viewType
) {

    private var binding //创建自己的layout布局
            : ImCustAnchorLiveViewBinding? = null
    override fun addViewToMessageContainer() {
        binding = ImCustAnchorLiveViewBinding.inflate(
            LayoutInflater.from(parent.context), messageContainer, true
        )
    }

    //去掉背景
    override fun onMessageBackgroundConfig(messageBean: ChatMessageBean?) {
        baseViewBinding.messageContainer.setBackgroundResource(R.color.title_transfer)
    }



    override fun bindData(message: ChatMessageBean?, lastMessage: ChatMessageBean?) {
        super.bindData(message, lastMessage)
        currentMessage = message
        val bean = message!!.messageData.message.attachment as CusAnchorLiveAttachment
            ?: return

        loge(" 直播间红包的数据:${bean.title}")
        binding?.let {
            it.title.text="     "+bean.title
            GlideUtil.ImageLoad(parent.context,bean.cover,it.imgCover)
            it.tvLiveName.text="直播人："+bean.nickname
            //主播头像昵称
            GlideUtil.ImageLoad(parent.context,bean.headimg,it.imgHead)
            it.tvName.text=bean.nickname




            var b =CusShareLiveAttachment()
            b.anchorId=bean.uid
            b.liveId=bean.live_id
            it.llItem.setSingleClickListener {
                RxBus.getDefault().post(
                    RxBusBean(
                        CustSignKey.CHAT_LIVE_URL,
                        CustSignKey.CHAT_LIVE_URL, b)
                )
            }

//            val text = bean.nickName+"正在直播，欢迎来观看 "+bean.liveUrl
//            copyToClipboard(this,text)

//            it.llItem.setOnLongClickListener {
//                val text = bean.nickName+"正在直播，欢迎来观看 "+bean.liveUrl
//                copyToClipboard(parent.context,text)
//                true
//            }

        }

    }
    inner class ListAdapter :
        QuickAdapter<UserInfoTagAentBean>(R.layout.tag_agent_item, convert = { helper, item ->
            if (item.type==1){
                //是imgTag
                helper.setGone(R.id.imgTag,false)
                    .setGone(R.id.tvAgent,true)
                GlideUtil.ImageLoad(parent.context,item.imgTag,helper.getView(R.id.imgTag))
            }else{
                helper.setGone(R.id.imgTag,true)
                    .setGone(R.id.tvAgent,false)

                helper
                    .setText(R.id.tvAgent,item.name)
                when (item.agentLevel) {
                    "1" -> helper.setBackgroundResource(R.id.tvAgent, R.drawable.shape_tag_sheng)
                    "2" -> helper.setBackgroundResource(R.id.tvAgent, R.drawable.shape_tag_shi)
                    "3" -> helper.setBackgroundResource(R.id.tvAgent, R.drawable.shape_tag_qu)
                }

            }


        })
}